// pages/new/new.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tips: '',
    userName: '',
    guardCardNo1: '',
    guardCardNo2: '',
    showTips: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  updateUser: function () {
    var that = this;
    if (that.data.userName == '') {
      that.setData({
        showTips: true,
        tips: '请输入姓名'
      });
    } else if (that.data.guardCardNo1 == '') {
      that.setData({
        showTips: true,
        tips: '请输入门禁卡号'
      });
    } else if (that.data.guardCardNo2 == '') {
      that.setData({
        showTips: true,
        tips: '请再次输入门禁卡号'
      });
    } else if (that.data.guardCardNo1 != that.data.guardCardNo2) {
      that.setData({
        showTips: true,
        tips: '两次卡号输入不一致'
      });
    } else {
      that.setData({
        showTips: false,
        tips: ''
      });
      wx.setStorageSync('userName', that.data.userName);
      wx.setStorageSync('guardCardNo', that.data.guardCardNo1);
      wx.redirectTo({
        url: '../user/user',
      })
    }
  
  },

  addUserName: function (e) {
    var that = this;
    that.setData({
      userName: e.detail.value
    });
  },

  addGuardCardNo1: function (e) {
    var that = this;
    that.setData({
      guardCardNo1: e.detail.value
    });
  },

  addGuardCardNo2: function (e) {
    var that = this;
    that.setData({
      guardCardNo2: e.detail.value
    });
  },

  changeToUser: function () {
    wx.redirectTo({
      url: '../user/user',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})